//到货通知单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var name=thisform.find('input[name=name]').val();
		var value=thisform.find('input[name=value]').val();
		// console.log(inbound_status);
		// return false;
		$('#baseConfigDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#baseConfigDatagrid').datagrid({ 
			queryParams:{
				name:name,
				value:value
			}
		});
	})
	$('#baseConfigDatagrid').datagrid({
		//url:getarrivalUrl+"?randnum="+Math.floor(Math.random()*1000000),
		queryParams:{
			status:0//未审核
		},
		url:getarrivalUrl,
		title:'基本设置',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'en_name',title:'变量名称',sortable:true},
		{field:'name',title:'名称',sortable:true},
		{field:'value',title:'值'},
		{field:'add_time',title:'添加时间',sortable:true}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
baseConfigObj={
	addBar:function(){
		$('#baseConfigAddDialog').dialog('open').dialog('setTitle','添加');
		$('#baseConfigAddForm').form('clear');
		$('#baseConfigGroup').combobox('select',2);
	},
	editBar:function(){//显示编辑框
		var baseConfigRow=$('#baseConfigDatagrid').datagrid('getSelections');
        if (baseConfigRow.length>1){		            	
            $.messager.alert('提示','一次只能修改一条记录!','info');
        }else if(baseConfigRow.length==1){            	
        	$('#baseConfigEditDialog').dialog('open').dialog('setTitle','编辑');
            $('#baseConfigEditForm').form('load',baseConfigRow[0]);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	removeBar:function(){
		var baseConfigRow=$('#baseConfigDatagrid').datagrid('getSelections');
        if (baseConfigRow.length>0){
        	$.messager.confirm('删除提示','真的要删除这'+baseConfigRow.length+'个信息吗?删除将不能再恢复！',function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<baseConfigRow.length;i++){
                		ids.push(baseConfigRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(baseConfigDelUrl,{id:id},function(result){
                        if (result.status){
                            $('#baseConfigDatagrid').datagrid('reload');
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	add:function(url){
		$('#baseConfigAddForm').form('submit',{
			url:url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	var result=eval('('+result+')');
                if(!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#baseConfigAddDialog').dialog('close');  
                    });
                }else{
                    $('#baseConfigAddDialog').dialog('close');       
                    $('#baseConfigDatagrid').datagrid('reload'); 
                }
            },
		});
	},
	save:function(url){
		$('#baseConfigEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	 var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#baseConfigEditDialog').dialog('close');
                    });
                }else{
                    $('#baseConfigEditDialog').dialog('close');      
                    $('#baseConfigDatagrid').datagrid('reload');    
                }
            }
        });
	},
	showAll:function(){
		$('#baseConfigDatagrid').datagrid({ queryParams:'status:0'});
	},
	examineBar:function(value){
		var baseConfigRow=$('#baseConfigDatagrid').datagrid('getSelections');
		if(value==1){
			var text='确定审核通过吗！';
		}
		if(value==2){
			var text='确定审核不通过吗！';
		}
        if (baseConfigRow.length>0){
        	$.messager.confirm('审核提示',text,function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<baseConfigRow.length;i++){
                		ids.push(baseConfigRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(examineUrl,{id:id,value:value},function(result){
                        if (result.status){
                            $('#baseConfigDatagrid').datagrid('reload');
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	}
}